package com.library.bookClass.service;

import com.framework.Page;
import com.library.bookClass.dao.BookClassDaoImpl;
import com.library.entity.BookClass;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
@Transactional(readOnly=false)
public class BookClassServiceImpl {
	
	@Resource
	private BookClassDaoImpl bookClassDaoImpl;
	
	public void addBookClass(BookClass bc){
		this.bookClassDaoImpl.saveBookClass(bc);
	}

	@Transactional(readOnly=true)
	public BookClass getBookClass(int bookClassId){
		return this.bookClassDaoImpl.getBookClass(bookClassId);
	}
	
	public void editBookClass(BookClass bookClass){
		this.bookClassDaoImpl.updateBookClass(bookClass);
	}
	
	public void deleteBookClass(int bookClassId){
		BookClass bc = this.getBookClass(bookClassId);

		this.bookClassDaoImpl.deleteBookClass(bc);
	}

	/*删除多个图书类别*/
	public void deleteBookClassGroup(int[] bookClasses){
		BookClass bc = null;
		for(int i = 0;i < bookClasses.length;++i){
			bc = this.getBookClass(bookClasses[i]);
			this.bookClassDaoImpl.deleteBookClass(bc);
		}

	}

	@Transactional(readOnly=true)
	/*查找全部图书类别*/
	public List<BookClass> getAllBookClasses(){
		return this.bookClassDaoImpl.getAll();
	}

	/*通过员工查找图书 分页*/
	@Transactional(readOnly=true)
	public Page<BookClass> getBookClassPage(int pageNum, int pageSize,Map paramsMap){
		return this.bookClassDaoImpl.findBookClassPage(pageNum,pageSize,paramsMap);
	}
}
